package com.xx.contoller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xx.entity.Employees;
import com.xx.entity.PageResult;
import com.xx.service.IEmployeesService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;

import java.math.BigDecimal;

@SpringBootTest
@AutoConfigureMockMvc
public class EmployeesController {
    @Autowired
    IEmployeesService iEmployeesService;
    //新增
    @Test
    void insert()  {
        Employees employee = new Employees();
        employee.setLoginName("admina");
        employee.setEmpName("admins");
        employee.setPassword("123456");
        employee.setPosition("User");
        employee.setEmail("123@example.com");
        employee.setPhoneNumber("1798978987");
        employee.setSalary(new BigDecimal("10000.00"));
        iEmployeesService.insert(employee);
    }

    //删除
    @Test
    void delete() {
        iEmployeesService.removeById(3);
    }

    //修改
    @Test
    void update() {
        Employees employee = new Employees();
        employee.setEmployeeId(46);
        employee.setLoginName("admina1");
        employee.setEmpName("admins1");
        employee.setPassword("123456");
        employee.setPosition("User1");
        employee.setEmail("123456@example.com");
        employee.setPhoneNumber("71456324587");
        employee.setSalary(new BigDecimal("11000.00"));
        iEmployeesService.updateById(employee);
    }

    @Test
    void getById() {
        iEmployeesService.getById(45);
    }

    //分页
    @Test
    void page() {
        Page page = new Page<>(1,5);
        QueryWrapper<Employees> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("login_name","3");
        IPage<Employees> employeesIPage = iEmployeesService.page(page,queryWrapper);
        System.out.println(PageResult.of(employeesIPage));
    }
}
